package com.solome.ui;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g2d.Animation.PlayMode;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Disposable;
import com.solome.util.GifDecoder;

/**
 * @author soells
 * @E-mail:soells@foxmail.com
 * @version 创建时间：2014年10月24日 下午2:58:23
 * @DES 程序的简单说明
 */

public class SoGif extends Actor implements Disposable {
	Animation animation;
	float stateTime;

	public SoGif(String path, PlayMode mode, float x, float y) {
		// TODO Auto-generated constructor stub
		animation = GifDecoder.loadGIFAnimation(mode, Gdx.files.internal(path)
				.read());
		this.setPosition(x, y);
	}

	public SoGif(String path, PlayMode mode) {
		// TODO Auto-generated constructor stub
		animation = GifDecoder.loadGIFAnimation(mode, Gdx.files.internal(path)
				.read());
	}

	@Override
	public void draw(Batch batch, float parentAlpha) {
		stateTime += Gdx.graphics.getDeltaTime();
		TextureRegion currentFrame = animation.getKeyFrame(stateTime, true);
		batch.draw(currentFrame, getX(), getY());
		this.setWidth(currentFrame.getRegionWidth());
		this.setHeight(currentFrame.getRegionHeight());
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		TextureRegion[] region = animation.getKeyFrames();
		for (TextureRegion textureRegion : region) {
			textureRegion.getTexture().dispose();
		}
	}

	// @Override
	// public void dispose() {
	// // TODO Auto-generated method stub
	// animation = null;
	// }

	// public float getX() {
	// return x;
	// }
	//
	// public void setX(float x) {
	// this.x = x;
	// }
	//
	// public float getY() {
	// return y;
	// }
	//
	// public void setY(float y) {
	// this.y = y;
	// }
}
